<template>
	<view>
		<view class="card">
			<view class="title u-flex">{{$z.$t("支付方式")}}</view>

			<view v-for="(item, key) in zffs" @click="itemtap(item)" :key="key" class="item u-flex">
				<u--image :showLoading="true" :src="item.src" width="50rpx" height="50rpx" mode="widthFix"
					style="margin: 0" radius="20rpx"></u--image>
				<view class="text">
					{{ $z.$t(item.text1 )}}
				</view>
				<view v-if="item.type != value" class="xzicon" :class="{ active: item.type == value }"></view>
				<view v-else class="xziconActive">
					<u-icon name="checkmark" color="#fff" size="14"></u-icon>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import config from "@/config/index.js";
	export default {
		name: "payment",
		props: {
			ChargeCarSys: {
				type: Object,
				default: () => {},
			},
			value: {
				type: [String, Number],
				default: "01",
			},
		},
		data() {
			return {
				activeitem: {},
			};
		},
		asyncComputed: {
			async zffs() {
				if (!this.ChargeCarSys.type) {
					return [];
				}
				let zfms = [];
				if (uni.$z.IsWeixinOrAlipay() == "weixin") {
					console.log('微信===================');
					zfms.push({
						type: "wx",
						text1: this.$z.$t("微信支付"),
						text2: this.$z.$t("推荐微信支付"),
						src: "http://img.gpsserver.cn:20080/240605/060513084117175_240605130841_TdWDjHBpZHMFD7km7MNCMp8rKwSif6n4.png",
					});
				} else {
					zfms.push({
						type: "zfb",
						text1: this.$z.$t("支付宝支付"),
						text2: this.$z.$t("急速、安全、新体验"),
						src: "http://img.gpsserver.cn:20080/240605/060513082217175_240605130822_kkCMtnfjQ42FFhSMjzCchjYReSSkwQWc.png",
					});
				}
				if (!this.$store.state.user.USearch.uUser) {
					await this.$store.dispatch("user/getuser");
				}
				let USearch = this.$store.state.user.USearch;
				zfms.push({
					type: "USearch",
					text1: this.$z.$t(`余额支付(现有余额￥${USearch.je / 100})`),
					text2: `${this.$z.$t("现有余额")}￥${USearch.je / 100}`,
					src: "http://img.gpsserver.cn:20080/240605/060513072517175_240605130725_HkSCFFKzwTXn8EBw2ZEmYErswBnMN6ws.png",
				});

				if (USearch.printid && USearch.printid != "") {
					// USearch.printid = "748204"
					let Card = await this.$store.dispatch("request/getRequest", {
						url: "/Card",
						data: {
							printid: USearch.printid,
						},
					});

					Card = Card[0] || {
						je: 0,
					};
					let Carddata = {
						type: "Card",
						src: "http://img.gpsserver.cn:20080/240605/060513085917175_240605130859_W8KytFiFHJrsRRAW7J6JBbGyQaX68KyY.png",
						text2: this.$z.$t("可使用绑定卡余额支付"),
					};
					if (Card.je == 0) {} else if ([0, 2].indexOf(Number(Card.type)) >= 0) {
						Carddata.text1 = this.$z.$t(`卡支付(现有余额￥${(Card.je / 100).toFixed(2)})`);
					} else if ([1, 3, 4].indexOf(Number(Card.type)) >= 0) {
						Carddata.text1 = this.$z.$t(`卡支付(${Card.je}次)`);
					} else if ([6].indexOf(Number(Card.type)) >= 0) {
						Carddata.text1 = this.$z.$t(`卡支付(剩余次数${Card.je}次/日)`);
					} else if ([5].indexOf(Number(Card.type)) >= 0) {
						Carddata.text1 = this.$z.$t(`卡支付(剩余时长${(Card.je / 60).toFixed(1)}小时)`);
					}
					if (Carddata.text1) {
						zfms.push(Carddata);
					}
				}
				if (USearch.je != 0) {
					let zfUSearch = zfms.find((e) => {
						return e.type == "USearch";
					});
					this.itemtap(zfUSearch);
				} else {
					this.itemtap(zfms[0]);
				}
				return zfms;
			},
		},
		watch: {},
		methods: {
			async init() {},
			itemtap(item) {
				this.activeitem = item;
				this.$emit("input", item.type);
			},
		},
	};
</script>

<style lang="scss" scoped>
	.card {
		margin: 30rpx 0rpx;
		background: #fff;
		padding-bottom: 30rpx;
		padding-top: 18rpx;
		padding-left: 30rpx;
		padding-right: 30rpx;
		border-radius: 20rpx;

		.title {
			font-size: 34rpx;
			font-weight: bold;
			height: 70rpx;
		}

		.item {
			height: 80rpx;

			.text {
				line-height: 40rpx;
				padding-left: 16rpx;
				width: 0;
				flex: 1;
				font-size: 28rpx;
			}

			.xziconActive {
				width: 40rpx;
				height: 40rpx;
				background: $u-primary;
				border-radius: 50%;
				box-sizing: border-box;

				display: flex;
				justify-content: center;
				align-items: center;


			}

			.xzicon {
				width: 40rpx;
				height: 40rpx;
				border: 4rpx solid $uni-border-color;
				border-radius: 50%;
				box-sizing: border-box;

				&.active {
					border-color: $u-primary;
					position: relative;

					&::after {
						position: absolute;
						top: 50%;
						left: 50%;
						transform: translate(-50%, -50%);
						content: "";
						display: block;
						width: 20rpx;
						height: 20rpx;
						background-color: $u-primary;
						border-radius: 50%;
						margin: 0 auto;
					}
				}
			}
		}
	}
</style>